{include file="header"}
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="postheader">
                <div class="w35">
                    <i class="layui-icon">&#xe6ed;</i>
                    电视台放送剧集信息录入窗口
                </div>
                <div class="w25"><span class="x-red">*</span>作品名:<span class="x-red">{$work.title}</span> </div>
                <div class="w25 dac">
                    <label class="layui-form-label childlabel"><span class="x-red">*</span>该话番型</label>
                    <select name="fan_cat" lay-filter="fan_cat" class="nosel">
                        <option value="2" {if $item && $item.fan_cat eq 2}selected{/if}>常规番</option>
                        <option value="1" {if $item && $item.fan_cat eq 1}selected{/if}>季番</option>
                        <option value="4" {if $item && $item.fan_cat eq 4}selected{/if}>电影</option>
                        <option value="5" {if $item && $item.fan_cat eq 5}selected{/if}>OVA</option>
                    </select>
                </div>
            </div>
            <input type="hidden" name="dbname" value="tv">
            <input type="hidden" name="id" value="{$item.id}">
            <input type="hidden" name="work_id" value="{$item.work_id}">
            <fieldset class="layui-elem-field" style="margin-top: 50px;">
                <legend>基本信息</legend>
                <div class="layui-field-box">
                    <div class="layui-form-item">

                        <div class="layui-inline special_cat_input" {if !$item}style="display: none;"{else}{if $item.fan_cat neq 3}style="display: none;"{/if}{/if}>
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>特殊番类型</label>
                            <div class="layui-input-inline">
                                <select name="special_cat" lay-filter="special_cat" class="nosel">
                                    <option value="1" {if $item && $item.special_cat eq 1}selected{/if}>浓缩番</option>
                                    <option value="2" {if $item && $item.special_cat eq 2}selected{/if}>电影</option>
                                    <option value="3" {if $item && $item.special_cat eq 3}selected{/if}>OVA</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>制作类型</label>
                            <div class="layui-input-inline">
                                <select name="make_cat" lay-filter="make_cat" >
                                    <option value="1" {if $item && $item.make_cat eq 1}selected{/if}>原作漫改</option>
                                    <option value="2" {if $item && $item.make_cat eq 2}selected{/if}>动画组原创</option>
                                    <option value="3" {if $item && $item.make_cat eq 3}selected{/if}>停播</option>
                                    <option value="4" {if $item && $item.make_cat eq 4}selected{/if}>重播</option>
                                </select>
                            </div>
                        </div>
                        <div class="layui-inline replay_make_cat_input" {if !$item}style="display: none;"{/if}>
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>重播类型</label>
                            <div class="layui-input-inline">
                                <select name="replay_make_cat" class="nosel">
                                    <option value="1" {if $item && $item.replay_make_cat eq 1}selected{/if}> <span>原作漫改</span> </option>
                                    <option value="2" {if $item && $item.replay_make_cat eq 2}selected{/if}> <span>动画组原创</span> </option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline" >
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>
                              <span id="words1str">{if in_array($item['fan_cat'],[4,5])}编号{else}话数{/if}</span>
                            </label>
                            <div class="layui-input-inline quarter_input wauto" {if !$item}style="display: none;"{else}{if $item.fan_cat neq 1}style="display: none;"{/if}{/if}>
                                第<input type="text" name="quarter" value="{$item?$item.quarter:''}" lay-verify="" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">季;
                            </div>
                            <div class="layui-input-inline wauto">
                                第<input type="text" data-check="1" data-premise="make_cat,quarter,fan_cat,special_cat" name="words1" value="{$item?$item.words1:''}"  autocomplete="off" class="layui-input nosel number"  style="width: 70px;display: inline-block;">
                                <span id="words1str2">{if in_array($item['fan_cat'],[4,5])}部{else}话{/if}</span>
                            </div>
                            <div class="layui-input-inline words2_input wauto" {if ($item.special_cat neq 1) OR ($item.fan_cat neq 3)}style="display: none;"{/if}>
                                ~
                                第<input type="text" name="words2" value="{$item?$item.words2:''}" lay-verify="" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">话;
                            </div>
                            <div class="layui-input-inline" style="height: 30px;line-height: 30px;">
                                <input type="hidden" name="zc" value="{$item.zc}">
                                {if $item.zc eq 1}
                                （<span class="zctext">正常</span>）
                                {elseif $item.zc eq 2}
                                （<span class="zctext">特殊Ⅰ</span>）
                                {elseif $item.zc eq 3}
                                （<span class="zctext">特殊Ⅱ</span>）
                                {/if}
                            </div>

                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>标题名称(中)</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" value="{$item?$item.title:''}"  autocomplete="off" class="layui-input nosel" >
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>(日)</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title_jp" value="{$item?$item.title_jp:''}"  autocomplete="off" class="layui-input nosel" >
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>放送日期</label>
                            <div class="layui-input-inline">
                                <input type="text" name="add_time" value="{$item.add_time?date('Y年m月d日',$item['add_time']):date('Y年m月d日',time())}" id="add_time"  autocomplete="off" class="layui-input" >
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>时长</label>
                            <div class="layui-input-inline">

                                <select name="tvlenth" lay-filter="tvlenth" class="nosel">
                                    <option value="1" {if $item && $item.tvlenth eq 1}selected{/if}>常规25分钟</option>
                                    <option value="2" {if $item && $item.tvlenth eq 2}selected{/if}>特别篇</option>
                                </select>

                            </div>
                        </div>
                        <div class="layui-inline tvother_input" {if !$item}style="display: none;"{/if} {if $item && $item.tvlenth neq 2}style="display: none;"{/if}>
                            <label class="layui-form-label childlabel"></label>
                            <div class="layui-input-inline">
                                <input type="text" name="tvother" value="{$item?$item.tvother:''}" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">小时特别篇
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label childlabel"><span class="x-red">*</span>播出频道</label>
                        <!--tvstation-->
                        <div class="layui-input-inline">
                            <button type="button" class="layui-btn" onclick="selcompany()">点击选择</button>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label"><span class="x-red"></span></label>
                        <div class="layui-input-inline">
                            <table class="layui-table" id="tvstationlist">
                                {if $item}
                                {volist name="channel" id="com"}
                                <tr class="kid_{$com.id}" data-id="">
                                    <td>{if $com.logo}<img src="{$com.logo|formatImg}" alt="" width="50">{/if} </td>
                                    <td>{$com.title}</td>
                                    <td>
                                        <div style="display: none;"><input type="checkbox" style="" name="tvstation" lay-skin="primary" value="{$com.id}"  checked></div>
                                        <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" onclick="delcompany(this)">删除</a>
                                    </td>
                                </tr>
                                {/volist}
                                {/if}
                            </table>
                        </div>
                    </div>
                    <div class="layui-form-item mhdy">
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>漫画对应:</label>
                            <div class="layui-inline">
                                (总话数)File.<input type="text" name="comics_words_file1" value="{$item?$item.comics_words_file1:''}" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">
                            </div>

                            <div class="layui-inline comics_words_file2" {if !$item.comics_words_file2}style="display: none;"{/if}>~</div>
                            <div class="layui-inline comics_words_file2" {if !$item.comics_words_file2}style="display: none;"{/if}>
                                <input type="text" name="comics_words_file2" value="{$item?$item.comics_words_file2:''}" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">
                            </div>
                            <div class="layui-inline">
                                {if !$item.comics_rolls_2}
                                <a href="javascript:;" class="iconsubadd add" id="comics_words_file">+</a>
                                {else}
                                <a href="javascript:;" class="iconsubadd sub" id="comics_words_file">-</a>
                                {/if}
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label childlabel"><span class="x-red">*</span>单行本</label>
                            <div class="layui-inline">
                                第<input type="text" name="comics_rolls_1" value="{$item.comics_rolls_1}" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">卷
                            </div>
                            <div class="layui-inline">
                                File.<input type="text" name="comics_rolls_1_file" value="{$item.comics_rolls_1_file}" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">
                            </div>
                            <div class="layui-inline comics_rolls_2" {if !$item.comics_rolls_2}style="display: none;"{/if}>-</div>
                            <div class="layui-inline comics_rolls_2" {if !$item.comics_rolls_2}style="display: none;"{/if}>
                                第<input type="text" name="comics_rolls_2" value="{$item?$item.comics_rolls_2:''}" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">卷
                            </div>
                            <div class="layui-inline comics_rolls_2" {if !$item.comics_rolls_2}style="display: none;"{/if}>
                                File.<input type="text" name="comics_rolls_2_file" value="{$item?$item.comics_rolls_2_file:''}" autocomplete="off" class="layui-input nosel number" style="width: 70px;display: inline-block;">
                            </div>
                            <div class="layui-inline">
                                {if !$item.comics_rolls_2}
                                <a href="javascript:;" class="iconsubadd add" id="comics_rolls">+</a>
                                {else}
                                <a href="javascript:;" class="iconsubadd sub" id="comics_rolls">-</a>

                                {/if}
                            </div>
                        </div>
                    </div>

                </div>
            </fieldset>
            <fieldset class="layui-elem-field">
                <legend>制作人员</legend>
                <div class="layui-field-box">
                    <fieldset class="layui-elem-field">
                        <legend>正片</legend>
                        <div class="layui-field-box">
                            {for start="1" end="15"}
                            <div class="layui-form-item staff">
                                <label class="layui-form-label">
                                    <p class="zh">{$catarray[$i]['zh']}</p>
                                    <p class="jp">{$catarray[$i]['jp']}</p>
                                </label>
                                <div class="layui-inline staff_{$i}">
                                    {if isset($staff[$i]) && count($staff[$i])>=1}
                                    {foreach $staff[$i] as $val}
                                    <div class="layui-inline stafflists" data-cat="{$i}">
                                        <input type="text" name="staff_zh" value="{$val.uname}" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">
                                        <span>-</span>
                                        <input type="text" name="staff_jp" value="{$val.uname_jp}" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">
                                    </div>
                                    {/foreach}
                                    {else}
                                    <div class="layui-inline stafflists" data-cat="{$i}">
                                        <input type="text" name="staff_zh" value="" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">
                                        <span>-</span>
                                        <input type="text" name="staff_jp" value="" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">
                                    </div>
                                    {/if}
                                </div>
                                <div class="layui-inline">
                                    <a href="javascript:;" class="layui-btn layui-btn-xs" onclick="addstaff({$i})">添加</a>
                                    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" onclick="substaff({$i})">删除</a>

                                </div>
                            </div>
                            {/for}
                        </div>
                    </fieldset>
                    <fieldset class="layui-elem-field">
                        <legend>OP</legend>
                        <div class="layui-field-box">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label childlabel"> <span class="x-red"></span> 编号</label>
                                    <div class="layui-inline">
                                        <input type="text" name="op_code" value="{$item?$item.op_code:''}" autocomplete="off" class="layui-input inline nosel" placeholder="">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label childlabel"> <span class="x-red"></span> 曲目</label>
                                    <div class="layui-inline">
                                        <input type="text" name="op_title" value="{$item?$item.op_title:''}" autocomplete="off" class="layui-input inline nosel" placeholder="">
                                    </div>
                                </div>
                            </div>
                            {for start="15" end="21"}
                            <div class="layui-form-item staff">
                                <label class="layui-form-label">
                                    <p class="zh">{$catarray[$i]['zh']}</p>
                                    <p class="jp">{$catarray[$i]['jp']}</p>
                                </label>
                                <div class="layui-inline staff_{$i}">
                                    {if isset($staff[$i]) && count($staff[$i])>=1}
                                    {foreach $staff[$i] as $val}
                                    <div class="layui-inline stafflists" data-cat="{$i}">
                                        <input type="text" name="staff_zh" value="{$val.uname}" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">
                                        <span>-</span>
                                        <input type="text" name="staff_jp" value="{$val.uname_jp}" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">
                                    </div>
                                    {/foreach}
                                    {else}
                                    <div class="layui-inline stafflists" data-cat="{$i}">
                                        <input type="text" name="staff_zh" value="" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">
                                        <span>-</span>
                                        <input type="text" name="staff_jp" value="" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">
                                    </div>
                                    {/if}

                                </div>
                                <div class="layui-inline">
                                    <a href="javascript:;" class="layui-btn layui-btn-xs" onclick="addstaff({$i})">添加</a>
                                    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" onclick="substaff({$i})">删除</a>

                                </div>
                            </div>
                            {/for}

                        </div>
                    </fieldset>
                    <fieldset class="layui-elem-field">
                        <legend>ED</legend>
                        <div class="layui-field-box">
                            <div class="layui-form-item">
                                <div class="layui-inline">
                                    <label class="layui-form-label childlabel"> <span class="x-red"></span> 编号</label>
                                    <div class="layui-inline">
                                        <input type="text" name="ed_code" value="{$item?$item.op_code:''}" autocomplete="off" class="layui-input inline nosel" placeholder="">
                                    </div>
                                </div>
                                <div class="layui-inline">
                                    <label class="layui-form-label childlabel"> <span class="x-red"></span> 曲目</label>
                                    <div class="layui-inline">
                                        <input type="text" name="ed_title" value="{$item?$item.op_title:''}" autocomplete="off" class="layui-input inline nosel" placeholder="">
                                    </div>
                                </div>
                            </div>
                            {for start="21" end="27"}
                            <div class="layui-form-item staff">
                                <label class="layui-form-label">
                                    <p class="zh">{$catarray[$i]['zh']}</p>
                                    <p class="jp">{$catarray[$i]['jp']}</p>
                                </label>
                                <div class="layui-inline staff_{$i}">
                                    {if isset($staff[$i]) && count($staff[$i])>=1}
                                    {foreach $staff[$i] as $val}
                                    <div class="layui-inline stafflists" data-cat="{$i}">
                                        <input type="text" name="staff_zh" value="{$val.uname}" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">
                                        <span>-</span>
                                        <input type="text" name="staff_jp" value="{$val.uname_jp}" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">
                                    </div>
                                    {/foreach}
                                    {else}
                                    <div class="layui-inline stafflists" data-cat="{$i}">
                                        <input type="text" name="staff_zh" value="" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">
                                        <span>-</span>
                                        <input type="text" name="staff_jp" value="" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">
                                    </div>
                                    {/if}

                                </div>
                                <div class="layui-inline">
                                    <a href="javascript:;" class="layui-btn layui-btn-xs" onclick="addstaff({$i})">添加</a>
                                    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" onclick="substaff({$i})">删除</a>
                                </div>
                            </div>
                            {/for}
                        </div>
                    </fieldset>
                </div>
            </fieldset>
            <fieldset class="layui-elem-field seiyuuhide">
                <legend>该话出场者</legend>
                <div class="layui-field-box">
                    <div class="tips">(包括本话出场的剧中角色以及相对应的的声优，若出场角色无台词，则声优可勾选无)</div>
                    <div class="layui-card-header seiyuuhide">
                        <button type="button" class="layui-btn layui-btn-primary" onclick="addline()">添加</button>
                        <button type="button" class="layui-btn layui-btn-primary" onclick="addlines()">批量添加</button>
                        <button type="button" class="layui-btn layui-btn-primary selobj" onclick="sel()" data-type="sel">批量选择</button>
                        <button type="button" class="layui-btn layui-btn-danger" onclick="del()">删除</button>
                    </div>
                    <table class="layui-table layui-form" id="setyuu_list">
                        {volist name="seiyuulists" id="val"}
                        {php}
                            $id = "edit_".$key;
                        {/php}
                        <tr class="seiyuu_tr tr_{$id}">
                            <td width="80"> <div style="display: none;" class="selone"><input type="checkbox" name="selone" value="{$id}" lay-skin="primary" ></div></td>
                            <td>角色名：(中)<input type="text" name="role_zh" value="{$val.role_zh}" class="layui-input inline nosel"> (日)<input type="text" name="role_jp" value="{$val.role_jp}" class="layui-input inline nosel"></td>
                            <td>声优：(中)<input type="text" name="seiyuu_zh" value="{$val.seiyuu_zh}" class="layui-input inline seiyuu_input nosel"> (日)<input type="text" name="seiyuu_jp" value="{$val.seiyuu_jp}" class="layui-input inline seiyuu_input nosel"> <input type="checkbox" name="cat" data-index="{$id}" value="2" class="cat2" lay-filter="seiyuu_cat" title="无" lay-skin="primary"> <input type="checkbox" name="cat" value="3" class="cat3" data-index="{$id}" lay-filter="seiyuu_cat" title="未知" lay-skin="primary"> </td>
                        </tr>
                        {/volist}
                    </table>
                </div>
            </fieldset>


            <div class="layui-form-item">
                <input type="hidden" name="display" value="0">

                <button  type="button" class="layui-btn" lay-filter="add" lay-submit="">
                    提交
                </button>
                <button  class="layui-btn layui-btn-primary" type="button" lay-filter="temporary" lay-submit="">
                    暂存
                </button>
                <button  class="layui-btn layui-btn-primary cancel" type="button">
                    取消
                </button>
            </div>
        </form>
    </div>
</div>
<div id="addlines" style="display: none;">
    <form class="layui-form" style="margin-top: 35px;margin-left: 30px;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <input type="text" name="num" lay-verify="required" autocomplete="off" class="layui-input nosel number">
            </div>
            <div class="layui-inline">
                <button  type="button" class="layui-btn" lay-filter="addlines" lay-submit="">
                    添加
                </button>
            </div>
        </div>
    </form>
</div>
<div id="zcsel" style="display: none;">
    <form class="layui-form" style="margin-top: 35px;margin-left: 30px;">
        <div class="layui-form-item">
            <div class="layui-inline">
                <input type="radio" name="zcsel" lay-filter="zcsel" value="1" title="正常" {if $item.zc eq 1}checked{/if}>
                <input type="radio" name="zcsel" lay-filter="zcsel" value="2" title="特殊Ⅰ" {if $item.zc eq 2}checked{/if}>
                <input type="radio" name="zcsel" lay-filter="zcsel" value="3" title="特殊Ⅱ" {if $item.zc eq 3}checked{/if}>

            </div>
        </div>
    </form>
</div>
{if $item && $item.make_cat eq 3}
<script>
    $(function () {
        $('.nosel').attr("disabled",true)
        $('.nosel').css("backgroundColor","#e6e6e6")
        $('.seiyuuhide').hide();
    })
</script>
{/if}
{if ($item.fan_cat eq 4) OR ($item.fan_cat eq 5) }
<script>
    $(function () {
        $('.mhdy').hide()
        $('.replay_make_cat_input').hide()
    })
</script>
{else}
{if $item.make_cat eq 4}
<script>
    $(function () {
        $('.replay_make_cat_input').show()
    })
</script>
{/if}
{/if}
<script>
    layui.use(['laydate'],function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#add_time' //指定元素
            ,type:"date"
            ,format:"yyyy年MM月dd日"
        });
        $('#comics_words_file').click(function () {
            if($(this).hasClass("add")){
                $(this).removeClass("add")
                $(this).addClass("sub")
                $(this).text("-");
                $('.comics_words_file2').show()
            }else{
                $(this).addClass("add")
                $(this).removeClass("sub")
                $(this).text("+");
                $('[name="comics_words_file2"]').val(null)
                $('.comics_words_file2').hide()
            }
        })
        $('#comics_rolls').click(function () {
            if($(this).hasClass("add")){
                $(this).removeClass("add")
                $(this).addClass("sub")
                $(this).text("-");
                $('.comics_rolls_2').show()
            }else{
                $(this).addClass("add")
                $(this).removeClass("sub")
                $(this).text("+");
                $('[name="comics_rolls_2"]').val(null)
                $('[name="comics_rolls_2_file"]').val(null)
                $('.comics_rolls_2').hide()
            }
        })
        form.on('select(tvlenth)',function (data) {
            var val = data.value
            if(val==1){
                $('.tvother_input').hide()
            }else{
                $('.tvother_input').show()
            }
        })
        form.on('checkbox(seiyuu_cat)',function (data) {
            var id = $(data.elem).data("index")
            var val = data.value
            if(data.elem.checked){
                if(val==2){
                    $(`.tr_${id}`).find('.cat3').prop("checked",false)
                    $(`.tr_${id}`).find('.seiyuu_input').val("")
                    $(`.tr_${id}`).find('.seiyuu_input').attr("readonly",true)
                    $(`.tr_${id}`).find('.seiyuu_input').css("backgroundColor","#e6e6e6")
                }else if(val==3){
                    $(`.tr_${id}`).find('.cat2').prop("checked",false)
                    $(`.tr_${id}`).find('.seiyuu_input').val("???")
                    $(`.tr_${id}`).find('.seiyuu_input').css("backgroundColor","#fff")

                }
                form.render('checkbox');
            }else{
                if(val==2){
                    $(`.tr_${id}`).find('.seiyuu_input').val("")
                    $(`.tr_${id}`).find('.seiyuu_input').attr("readonly",false)
                    $(`.tr_${id}`).find('.seiyuu_input').css("backgroundColor","#fff")

                }else if(val==3){
                    $(`.tr_${id}`).find('.seiyuu_input').val("")
                }

            }

        });
        form.on('select(fan_cat)',function (data) {
            var val = data.value
            if(val==4 || val==5){
                $('.mhdy').hide()
                $('.replay_make_cat_input').hide()
                if(val==4){
                    $('[name="make_cat"] option').eq(3).attr("selected",true)
                    // $('.replay_make_cat_input').show()
                    $('[name="make_cat"]').attr("disabled",true)
                    getmovie()
                }else{
                    $('[name="make_cat"]').removeAttr("disabled")

                }
                $('.quarter_input').hide()
                $('#words1str').text("编号")
                $('#words1str2').text("部")
            }else{
                $('.mhdy').show()

                $('[name="make_cat"]').removeAttr("disabled")

                $('.show').hide()

                $('[name="special_cat"] option').eq(0).attr("selected",true)
                $('.special_cat_input').hide()
                $('.words2_input').hide()

                if(val==1){
                    $('.quarter_input').show()
                }else{
                    $('.quarter_input').hide()
                }
                $('#words1str').text("话数")
                $('#words1str2').text("话")

            }
            form.render()
        })
        form.on('select(special_cat)',function (data) {
            var val = data.value
            if(val==1){
                $('.words2_input').show()
            }else{
                $('.words2_input').hide()
            }
            form.render()
        })
        form.on('select(make_cat)',function (data) {
            var val = data.value
            if(val==4){
                var fan_cat = $('[name="fan_cat"]').val()
                if(fan_cat==4 || fan_cat==5){
                }else{
                    $('.replay_make_cat_input').show()
                }
                $('.nosel').attr("disabled",false)
                $('.nosel').css("backgroundColor","#fff")
                $('.seiyuuhide').show();

            }else{
                $('.replay_make_cat_input').hide()
                if(val==3){
                    $('.nosel').attr("disabled",true)
                    $('.nosel').css("backgroundColor","#e6e6e6")
                    $('.seiyuuhide').hide();
                }else{
                    $('.nosel').attr("disabled",false)
                    $('.nosel').css("backgroundColor","#fff")
                    $('.seiyuuhide').show();
                }
                //查看有没有重复
                let words1 = $('[name="words1"]').val()
                if(words1){
                    torequest($('[name="words1"]'),val,true)
                }

            }

            form.render()
        })
        //监听提交
        form.on('submit(temporary)', function(data) {
            let postfield = getfield(data)
            postfield.field.display=1

            request("POST",'{:url("tv/post")}',postfield.field,function (res,msg) {
                //发异步，把数据提交给php
                layer.alert(msg, {icon: 6}, function() {
                    xadmin.close();
                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                });
            })

            return false;
        });
        //监听提交
        form.on('submit(add)', function(data) {
            let postfield = getfield(data)

            request("POST",'{:url("tv/post")}',postfield.field,function (res,msg) {
                //发异步，把数据提交给php
                layer.alert(msg, {icon: 6}, function() {
                    xadmin.close();
                    // 可以对父窗口进行刷新
                    xadmin.father_reload();
                });
            })

            return false;
        });

        $('.zctext').click(function () {
            layer.open({
                type: 1,
                title:'',
                content: $('#zcsel')
                ,area: ['300px', '100px']
                ,success:function () {
                    //监听提交
                    form.on('radio(zcsel)', function(data) {
                        $('.zctext').text($(data.elem).attr("title"))
                        $('[name="zc"]').val(data.value)
                        var formData = {}

                        $('.replay_make_cat_input').show()
                        if(data.value==3){
                            $('.words2_input').show()
                        }else{
                            $('.words2_input').hide()
                        }
                        formData[`make_cat`] = 4
                        formSetVal(formData)

                        layer.closeAll()
                        return false;
                    });
                }
            });
        })
    })
    function getfield(data) {
        var staff=[];
        var stafflen = $('.stafflists').length
        var index = 0
        $('.stafflists').each(function () {
            var obj={
                cat:$(this).data("cat"),
                uname:$(this).find('[name="staff_zh"]').val(),
                uname_jp:$(this).find('[name="staff_jp"]').val(),
            };
            staff[index]=obj
            index ++;
        })
        data.field.staff=staff
        var seiyuu = [];
        $('.seiyuu_tr').each(function () {
            var index = $(this).index()
            var obj={
                role_zh: $(this).find('[name="role_zh"]').val(),
                role_jp:$(this).find('[name="role_jp"]').val(),
                seiyuu_zh:$(this).find('[name="seiyuu_zh"]').val(),
                seiyuu_jp:$(this).find('[name="seiyuu_jp"]').val(),
                cat:$(this).find('[name="cat"]:checked').val()?$(this).find('[name="cat"]:checked').val():1,
            }
            seiyuu[index] = obj
        })
        var tvstation=[]
        $('[name="tvstation"]').each(function () {
            tvstation.push($(this).val())
        })
        data.field.seiyuu=seiyuu
        data.field.tvstation=tvstation
        return data
    }
    function addstaff(id) {
        var html2=''
        html2 +=`<div class="layui-inline stafflists" data-cat="${id}">`
        html2 +=`<input type="text" name="staff_zh"  value="" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">`
        html2 +=`<span> - </span>`
        html2 +=`<input type="text" name="staff_jp"  value="" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">`
        html2 +='</div>'
        var make_cat = $('[name="make_cat"]').val()
        if(make_cat!=3){
            $('.staff_'+id).append(html2)
        }
    }
    function substaff(id) {
        $('.staff_'+id+'>.layui-inline:last-child').remove()
    }
    function addline(num) {
        if(!num){
            num = 1
        }
        var html = ''
        var trlen = $('#setyuu_list').children("tr").length
        for (var i = 1;i<=num;i++){
            var id = `add_${trlen+i}`
            html +=`<tr class="seiyuu_tr tr_${id}">`
            html +=`<td width="80"> <div style="display: none;" class="selone"><input type="checkbox" name="selone" value="${id}" lay-skin="primary" ></div></td>`
            html +=`<td>角色名：(中)<input type="text" name="role_zh" value="" class="layui-input inline nosel"> (日)<input type="text" name="role_jp" value="" class="layui-input inline nosel"></td>`
            html +=`<td>声优：(中)<input type="text" name="seiyuu_zh" value="" class="layui-input inline seiyuu_input nosel"> (日)<input type="text" name="seiyuu_jp" value="" class="layui-input inline seiyuu_input nosel"> <input type="checkbox" name="cat" data-index="${id}" value="2" class="cat2" lay-filter="seiyuu_cat" title="无" lay-skin="primary"> <input type="checkbox" name="cat" value="3" class="cat3" data-index="${id}" lay-filter="seiyuu_cat" title="未知" lay-skin="primary"> </td>`

            html +='</tr>'
        }
        var make_cat = $('[name="make_cat"]').val()
        if(make_cat!=3){
            $('#setyuu_list').append(html)
        }

        form.render()
    }
    function addlines() {
        var make_cat = $('[name="make_cat"]').val()
        if(make_cat!=3){
            layer.open({
                type: 1,
                title:'',
                content: $('#addlines')
                ,area: ['300px', '100px']
                ,success:function () {
                    //监听提交
                    form.on('submit(addlines)', function(data) {
                        addline(data.field.num)
                        layer.closeAll()
                        return false;
                    });
                }
            });
        }

    }
    function del() {
        var id;
        let seltype = $('.selobj').data("type")
        if(seltype==="sel"){
            id = [$('[name="selone"]').last().val()]
        }else{
            id = getselall()
        }
        for(let i in id){
            $(`.tr_${id[i]}`).remove()
        }
    }

    /**
     * @title 设置员工
     * @param datas
     */
    function setstaff(datas) {
        Object.keys(datas).forEach(function(key){

            var items = datas[key]
            if(items.length>0){
                var html=''

                var cat = items[0].cat
                $(`.staff_${cat}`).html('')
                for(var v=0;v<items.length;v++){
                    html +=`<div class="layui-inline stafflists" data-cat="${cat}">`
                    html +=`<input type="text" name="staff_zh" value="${items[v].uname}" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">`
                    html +=`<span>-</span>`
                    html +=`<input type="text" name="staff_jp" value="${items[v].uname_jp}" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">`
                    html +=`</div>`
                }

                $(`.staff_${cat}`).html(html)
            }

        });

    }

    /**
     * @title 设置声优
     * @param datas
     */
    function setseiyuu(datas) {
        var html=''
        $('#setyuu_list').html('')
        var trlen=0
        for(var i=0;i<datas.length;i++){
            var id = `add_${trlen+i}`
            html +=`<tr class="seiyuu_tr tr_${id}">`
            html +=`<td width="80"> <div style="display: none;" class="selone"><input type="checkbox" name="selone" value="${id}" lay-skin="primary" ></div></td>`
            html +=`<td>角色名：(中)<input type="text" name="role_zh" value="${datas[i].role_zh}" class="layui-input inline nosel"> (日)<input type="text" name="role_jp" value="${datas[i].role_jp}" class="layui-input inline nosel"></td>`
            html +=`<td>声优：(中)<input type="text" name="seiyuu_zh" value="${datas[i].seiyuu_zh}" class="layui-input inline seiyuu_input nosel"> (日)<input type="text" name="seiyuu_jp" value="${datas[i].seiyuu_jp}" class="layui-input inline seiyuu_input nosel">`
            if(datas[i].cat==2){
                html +=`<input type="checkbox" name="cat" data-index="${id}" value="2" class="cat2" checked lay-filter="seiyuu_cat" title="无" lay-skin="primary">`
            }else{
                html +=`<input type="checkbox" name="cat" data-index="${id}" value="2" class="cat2" lay-filter="seiyuu_cat" title="无" lay-skin="primary">`
            }
            if(datas[i].cat==3){
                html +=`<input type="checkbox" name="cat" value="3" class="cat3" data-index="${id}" checked lay-filter="seiyuu_cat" title="未知" lay-skin="primary">`
            }else{
                html +=`<input type="checkbox" name="cat" value="3" class="cat3" data-index="${id}" lay-filter="seiyuu_cat" title="未知" lay-skin="primary">`
            }
            html +='</td>'
            html +='</tr>'
        }
        $('#setyuu_list').html(html)

    }
    function addcompany(id,title,logo) {

        if($('body').find('.kid_'+id).length<=0){
            var html = "";
            html +=`<tr class="kid_${id}" data-id="${id}">`
            html +=`<td><img src="${logo}" alt="" width="50"> </td>`
            html +=`<td>${title}</td>`
            html +=`<td>`
            html +=`<div style="display: none;"><input type="checkbox" style="display: none" name="tvstation" lay-skin="primary" value="${id}"  checked></div>`
            html +=`<a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs" onclick="delcompany(this)">删除</a>`
            html +=`</td>`
            html +=`</tr>`
            $('#tvstationlist').append(html)
        }
    }
    function delcompany(obj) {
        $(obj).parent().parent().remove()
    }
    function selcompany() {
        xadmin.open("选择频道",'{:url("channel/index",["sel"=>true])}')
    }

    function getmovie() {
        var words1 = $('[name="words1"]').val()
        var work_id = $('[name="work_id"]').val()
        var tvlenth = $('[name="tvlenth"]').val()

        request("GET",'{:url("movie/getmans")}',{
            words1:words1,
            work_id:work_id,
            tvlenth:tvlenth
        },function (res,msg) {
            let staffArray = res.staffArray
            let seiyuu = res.seiyuu
            if(staffArray.length>0){
                for (let i in staffArray){
                    let cat= staffArray[i].id;
                    let lists = staffArray[i].lists;
                    if(lists.length>0){
                        $(`.staff_${cat}`).html('')
                        var html=''
                        for(let k in lists){
                            html +=`<div class="layui-inline stafflists" data-cat="${cat}">`
                            html +=`<input type="text" name="staff_zh" value="${lists[k].username}" autocomplete="off" class="layui-input inline nosel" placeholder="中文名称">`
                            html +=`<span>-</span>`
                            html +=`<input type="text" name="staff_jp" value="${lists[k].username_jp}" autocomplete="off" class="layui-input inline nosel" placeholder="日文名称">`
                            html +=`</div>`
                        }
                        $(`.staff_${cat}`).html(html)
                    }
                }
            }
            if(seiyuu.length>0){
                setseiyuu(seiyuu)
                // for(let s in seiyuu){
                //
                // }
            }
        })
    }
</script>
{include file="footer"}